<script type="text/ecmascript-6">
  import Navbar from '../../components/base/navbar.vue';
  import { Cache, cache_keys } from '../../utils/util';
  export default{
      name:"registration_detail",
      components:{
        Navbar
      },
      data(){
        return {
          isLogin: false,
          myID: this.$route.params.id,
          isLike: false,
          shareTip: false,
          isCoach: false
        }
      },
      methods:{
        goMap() {
          var url;
          const point = this.detail.address_point.split(','),
            latitude = Number(point[0]),
            longitude = Number(point[1]),
            name = this.detail.address_name,
            address = this.detail.address;

          url = 'http://apis.map.qq.com/tools/poimarker?type=0' +
            '&marker=coord:'+latitude+','+longitude+';' +
            'title:'+name+';' +
            'addr:'+address+
            '&key=5DZBZ-EN6AU-6NFVH-4SR2M-WEBF2-D3BPP&referer=myapp';
          window.location.href= url;

          /*const point = this.detail.address_point.split(','),
           latitude = Number(point[0]),
           longitude = Number(point[1]),
           name = this.detail.address_name,
           address = this.detail.address;
           this.$weixin.openLocation({
           latitude: latitude,
           longitude: longitude,
           name: name,
           address: address
           })*/
        },
        jump(page) {
            console.log(1);
          this.$router.push({ name: page, params: {id: this.myID} });
        },
        likeStatus(status) {
          this.isLike = !!status;
        },
        like(){
            if(this.isLogin){
                this.$store.dispatch('submitlike',this.myID);
            }else{
              this.$router.push({ name: 'login-quick', query: { source: this.$route.path } });
//              window.location.href="http://m.dev.tnf.ibrand.cc/#!/user/login/quick";
            }
        },
        likeComplete(like){
            this.isLike =!!like;
            switch (like){
              case 0:
                   this.$Message.show({text:"取消收藏成功"});
                   break;
              case 1:
                   this.$Message.show({text:"收藏成功"});
                   break;
            }
        }
      },
      created(){
         EventBus.$on("like-status",this.likeStatus);
         EventBus.$on("like-complete",this.likeComplete);
        this.$store.dispatch('queryActivityDeatil',this.myID);
        let entrance=this.$route.params.entrance;
        if(entrance=='registration') {
          console.log(Cache.get(cache_keys.token));
          this.isLogin = !!Cache.get(cache_keys.token);
          if( this.isLogin ) this.$store.dispatch('queryActivityUserState',this.myID);
        }
        else if(entrance=='coach'){
             this.isCoach =true;
         }
      },
      mounted(){

      },
      beforeDestory(){
          EventBus.$off("like-status");
          EventBus.$off("like-complete");
      },
      computed:{
        likeClass: function(){
          if(this.isLike) {
            return 'liked';
          }else{
            return 'like';
          }
        },
        statusClass: function(){
          const s1 = this.detail.status,
            s2 = this.state.member_status;
          switch (s1) {
            case 1:
              switch (s2) {
                default:
                  return 'red';
                case 1:
                  return 'black';
              }
              break;
            case 2:
              switch (s2) {
                case 1:
                  return 'black';
                case  2:
                  return 'blue';
              }
              break;
            case 4: case 5:
            switch (s2) {
              case 1:
                return 'black';
            }
            break;
          }
        },
        statusTxt: function(){
          const s1 = this.detail.status,
            s2 = this.state.member_status;

          switch (s1) {
            case 0:
              return '即将开始报名';
            case 1:
              switch (s2) {
                default:
                  return '立即报名';
                case 1:
                  return '活动已报名';
              }
              break;
            case 2:
              switch (s2) {
                default:
                  return '报名已截止';
                case 1:
                  return '未签到';
                case 2:
                  return '签到成功';
              }
              break;
            case 3:
              return '活动已结束';
            case 4:
              switch (s2) {
                default:
                  return '报名已截止';
                case 1:
                  return '活动已报名';
              }
              break;
            case 5:
              switch (s2) {
                default:
                  return '活动已满额';
                case 1:
                  return '活动已报名';
              }
              break;
          }
        },
        statusDisabled: function() {
          const s1 = this.detail.status,
            s2 = this.state.member_status;
          if(this.isLogin){
            if( s1==1 ){
              switch (s2) {
                default:
                  return true;
                case 0: case 3:
                return false;
              }
            }else{
              return true;
            }
          }else{
            if( s1==1 ){
              return false;
            }else{
              return true;
            }
          }
        },
         detail:{
             get(){
                 return this.$store.getters.getActivityDetail;
             }
         },
         state:{
            get(){
              return this.$store.getters.getActivityUserState
            }
         }
      }
  }
</script>
